package xml.catalogue.model;

import java.util.HashSet;
import java.util.Set;


public class Solicitation {
	
	private String id;
	
	private Group fromGroup;
	
	private Group toGroup;
	
	private Set<Item> itens;
	
	private int pendentItensNumber;
	
	public Solicitation(String id, Group fromGroup, Group toGroup, Set<Item> itens){
		this.id = id;
		this.fromGroup = fromGroup;
		this.toGroup = toGroup;
		this.itens = itens;
		pendentItensNumber = itens.size();
	}
	
	public Solicitation(String id, Group fromGroup, Group toGroup, int pendentItensNumber){
		this.id = id;
		this.fromGroup = fromGroup;
		this.toGroup = toGroup;
		this.pendentItensNumber = pendentItensNumber;
		itens = new HashSet<Item>();
	}

	public synchronized int getPendentItensNumber() {
		return pendentItensNumber;
	}

	public synchronized void setPendentItensNumber(int pendentItensNumber) {
		this.pendentItensNumber = pendentItensNumber;
	}
	
	public synchronized int decrementPendentItensNumber(){
		pendentItensNumber--;
		return pendentItensNumber;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Set<Item> getItens() {
		return itens;
	}

	public void setItens(Set<Item> itens) {
		this.itens = itens;
	}
	
	public boolean addItem(Item item){
		return itens.add(item);
	}

	public Group getFromGroup() {
		return fromGroup;
	}

	public void setFromGroup(Group fromGroup) {
		this.fromGroup = fromGroup;
	}

	public Group getToGroup() {
		return toGroup;
	}

	public void setToGroup(Group toGroup) {
		this.toGroup = toGroup;
	}

}
